package com.carlo.service;

import java.net.URI;

import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;

public abstract class AbstractMail {

	public ExchangeService service;
	
	public String temp;         //临时目录，用于存放邮件附件
	
	/**
	 * @throws Exception 
	 * 
	* @Title: initExchangeService 
	* @Description: 初始化exchange协议服务链接
	* @param @param username	邮箱账号
	* @param @param password	邮箱密码
	* @param @param demand    	邮箱对应exchange协议的域名
	* @return void    返回类型 
	* @author carlo
	* @throws
	 */
	public void initExchangeService(String username,String password,String demand) throws Exception{
		service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
		ExchangeCredentials credentials = new WebCredentials(username,password);
		service.setCredentials(credentials);
		try {
			service.setUrl(new URI("https://" + demand + "/ews/exchange.asmx"));
		} catch (Exception e) {
			throw new Exception("初始化exchange服务失败。" , e);
		}
	}

}
